package com.cz.nongyetongv5.activity;

import java.io.IOException;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.UUID;

import android.app.AlertDialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
import android.text.SpannableStringBuilder;
import android.text.TextWatcher;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout.LayoutParams;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.cz.nongyetongv5.R;
import com.cz.nongyetongv5.adapter.WheelViewAdapter;
import com.cz.nongyetongv5.adapter.config.CommonConstants;
import com.cz.nongyetongv5.adapter.dao.DatabaseHelper;
import com.cz.nongyetongv5.application.InitApplication;
import com.cz.nongyetongv5.bean.BeiJianDanWei;
import com.cz.nongyetongv5.bean.DuChaXunChaRecord;
import com.cz.nongyetongv5.bean.JianChaDanWei;
import com.cz.nongyetongv5.bean.JianChaHangYe;
import com.cz.nongyetongv5.bean.JianChaJieGuo;
import com.cz.nongyetongv5.bean.JianChaNeiRong;
import com.cz.nongyetongv5.bean.JianChaRenYuan;
import com.cz.nongyetongv5.bean.JianDuJianChaRecord;
import com.cz.nongyetongv5.bean.Photo;
import com.cz.nongyetongv5.bean.TextInfo;
import com.cz.nongyetongv5.bean.Town;
import com.cz.nongyetongv5.bean.User;
import com.cz.nongyetongv5.custom.dialog.CustomDialog;
import com.cz.nongyetongv5.custom.wheelview.TosAdapterView;
import com.cz.nongyetongv5.custom.wheelview.Utils;
import com.cz.nongyetongv5.custom.wheelview.WheelView;
import com.cz.nongyetongv5.custom.wheelview.TosAdapterView.OnItemSelectedListener;
import com.cz.nongyetongv5.utils.CharsetUtil;
import com.cz.nongyetongv5.utils.DialogUtil;
import com.cz.nongyetongv5.utils.ImageUtil;
import com.cz.nongyetongv5.utils.SerliazableUtil;

public class DuChaXunChaNewRecordActivity extends Fragment implements
		OnClickListener {

	private User user = null;

	private DatabaseHelper db = null;

	/**
	 * 所属区域
	 */
	private ViewGroup rl_jiandujiancha_item_suoshuquyu = null;

	/**
	 * 被检查单位
	 */
	private ViewGroup rl_jiandujiancha_item_beijiandanwei = null;

	/**
	 * 通讯地址
	 */
	private ViewGroup rlAdress = null;

	/**
	 * 负责人
	 */
	private ViewGroup rlFuZeRen = null;

	/**
	 * 联系方式
	 */
	private ViewGroup rlFangShi = null;

	/**
	 * 检查单位
	 */
	private ViewGroup rl_jiandujiancha_item_jianchadanwei = null;

	/**
	 * 受检单位的布局
	 */
	private ViewGroup llCreateDanWeiLayout = null;

	/**
	 * 检察人员
	 */
	private ViewGroup rl_jiandujiancha_item_jiancharenyuan = null;

	/**
	 * 检查行业
	 */
	private ViewGroup rl_jiandujiancha_item_jianchahangye = null;

	/**
	 * 检查记录
	 */
	private RelativeLayout rl_jiandujiancha_item_jianchajilu = null;

	/**
	 * 监管内容的item产地环境安全性等..的布局
	 */
	private ViewGroup jianGuanNeiRongItemLayout = null;

	/**
	 * �a地�h境的安全性
	 */
	private ViewGroup rlNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang = null;
	/**
	 * 绿色食品
	 */
	private ViewGroup rlNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang = null;
	/**
	 * 有机食品
	 */
	private ViewGroup rlNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang = null;
	/**
	 * 地理标志农产品
	 */
	private ViewGroup rlNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu = null;

	private ViewGroup rlNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu = null;

	private ViewGroup rlDuChaXunChaQiTa = null;

	/**
	 * 整改意见
	 */
	private ViewGroup rlZhengGaiYiJianItemLayout = null;

	/**
	 * 签名
	 */
	private ViewGroup rl_jiandujiancha_item_qianming = null;

	/**
	 * 拍照
	 */
	private ViewGroup rl_jiandujiancha_item_paizhao = null;

	/**
	 * 数据对象
	 */
	private DataBean dataBean = new DataBean();

	/**
	 * 点击按钮发生的事情的处理对象
	 */
	private OnClickExecute onClickExecute = null;

	/**
	 * Intent 传递的标志
	 */
	public static final int JIANCHADANWEI_REQUEST_CODE = 0;

	public static final int JIANCHARENYUAN_REQUEST_CODE = 1;

	public static final int QIANMING_REQUEST_CODE = 2;

	public static final int PAIZHAO_REQUEST_CODE = 3;

	/**
	 * 是否编辑模式
	 */
	private boolean isEditor = false;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
							 Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.duchaxuncha_newrecord, container,
				false);

		return view;
	}

	/**
	 * 初始化视图
	 */
	private void initView() {

		rl_jiandujiancha_item_suoshuquyu = (ViewGroup) getActivity()
				.findViewById(R.id.rl_jiandujiancha_item_suoshuquyu);

		rl_jiandujiancha_item_suoshuquyu.setOnClickListener(this);

		rl_jiandujiancha_item_beijiandanwei = (ViewGroup) getActivity()
				.findViewById(R.id.rl_jiandujiancha_item_beijiandanwei);
		rl_jiandujiancha_item_beijiandanwei.setOnClickListener(this);

		llCreateDanWeiLayout = (ViewGroup) getActivity().findViewById(
				R.id.llCreateBeiJianDanWeiLayout);

		rlAdress = (ViewGroup) getActivity().findViewById(R.id.rlAdress);
		rlAdress.setOnClickListener(this);

		rlFuZeRen = (ViewGroup) getActivity().findViewById(R.id.rlFuZeRen);
		rlFuZeRen.setOnClickListener(this);

		rlFangShi = (ViewGroup) getActivity()
				.findViewById(R.id.rlLianXiFangShi);
		rlFangShi.setOnClickListener(this);

		rl_jiandujiancha_item_jianchadanwei = (ViewGroup) getActivity()
				.findViewById(R.id.rl_jiandujiancha_item_jianchadanwei);
		rl_jiandujiancha_item_jianchadanwei.setOnClickListener(this);

		rl_jiandujiancha_item_jiancharenyuan = (ViewGroup) getActivity()
				.findViewById(R.id.rl_jiandujiancha_item_jiancharenyuan);
		rl_jiandujiancha_item_jiancharenyuan.setOnClickListener(this);

		// 查询出检查行业
		rl_jiandujiancha_item_jianchahangye = (ViewGroup) getActivity()
				.findViewById(R.id.rl_jiandujiancha_item_jianhangye);
		rl_jiandujiancha_item_jianchahangye.setOnClickListener(this);

		// 查询出检查记录
		rl_jiandujiancha_item_jianchajilu = (RelativeLayout) getActivity()
				.findViewById(R.id.rl_jiandujiancha_item_jianchajilu);

		rl_jiandujiancha_item_jianchajilu.setOnClickListener(this);

		// 查询出监管内容的item产地环境安全性等..的布局
		jianGuanNeiRongItemLayout = (ViewGroup) getActivity().findViewById(
				R.id.jianGuanNeiRongItemLayout);

		// 查询出产地环境的安全性布局
		rlNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang = (RelativeLayout) jianGuanNeiRongItemLayout
				.findViewById(R.id.rlNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang);
		rlNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang.setOnClickListener(this);

		// 查询出生产经营的规范性布局
		rlNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang = (RelativeLayout) jianGuanNeiRongItemLayout
				.findViewById(R.id.rlNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang);
		rlNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang.setOnClickListener(this);

		// 查询出产品质量的安全性布局
		rlNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang = (RelativeLayout) jianGuanNeiRongItemLayout
				.findViewById(R.id.rlNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang);
		rlNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang
				.setOnClickListener(this);

		// 查询包装标识的合法性布局
		rlNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu = (RelativeLayout) jianGuanNeiRongItemLayout
				.findViewById(R.id.rlNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu);

		rlNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu
				.setOnClickListener(this);

		// 查询出其他布局
		rlNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu = (RelativeLayout) jianGuanNeiRongItemLayout
				.findViewById(R.id.rlNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu);
		rlNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu.setOnClickListener(this);

		rlDuChaXunChaQiTa = (RelativeLayout) jianGuanNeiRongItemLayout
				.findViewById(R.id.rlDuChaXunChaQiTa);
		rlDuChaXunChaQiTa.setOnClickListener(this);

		// 查询出整改意见
		rlZhengGaiYiJianItemLayout = (RelativeLayout) jianGuanNeiRongItemLayout
				.findViewById(R.id.rlZhengGaiYiJianItemLayout);

		// 查询出整改意见
		rlZhengGaiYiJianItemLayout.setOnClickListener(this);

		// 查询出签名
		rl_jiandujiancha_item_qianming = (RelativeLayout) getActivity()
				.findViewById(R.id.rl_jiandujiancha_item_qianming);
		rl_jiandujiancha_item_qianming.setOnClickListener(this);

		// 查�出拍照
		rl_jiandujiancha_item_paizhao = (RelativeLayout) getActivity()
				.findViewById(R.id.rl_jiandujiancha_item_paizhao);

		rl_jiandujiancha_item_paizhao.setOnClickListener(this);

	}

	/**
	 * 初始化数据配置
	 */
	private void initConfig() {

		db = new DatabaseHelper(getActivity(), CommonConstants.DBNAME, null,
				CommonConstants.DATABASE_VERSION);

		user = (User) getActivity().getIntent().getSerializableExtra("user");

		onClickExecute = new OnClickExecute();

		List<DuChaXunChaRecord> records = SerliazableUtil
				.getDuChaXunChaRecordByState(0, this.user.getUsername());

		if (records.size() > 0 && dataBean.data == null) {
			dataBean.data = records.get(0);
		}

		if (dataBean.data == null) {

			dataBean.data = new DuChaXunChaRecord();

			dataBean.data.setUsername(this.user.getUsername());

		}

		if (dataBean.data != null
				&& !CharsetUtil.isNotNull(dataBean.data.getId())) {

			String id = UUID.randomUUID().toString().replaceAll("-", "");

			dataBean.data.setId(id);

		}

		/*
		 * 根据用户信息进行区域的初始化
		 */

		if (user.getCityId() != null) {

			dataBean.getData().getTowns()[0] = db.queryTownById(user
					.getCityId());
		}

		if (user.getArea() != null) {
			dataBean.getData().getTowns()[1] = db.queryTownById(user.getArea());

		}

		if (user.getTownId() != null) {
			dataBean.getData().getTowns()[2] = db.queryTownById(user
					.getTownId());
		}

		/**
		 * 查询出检查人员
		 */

		if (dataBean.checkJianChaRenYuan() == false) {

			List<JianChaRenYuan> jianChaRenYuans = db
					.queryAllJianChaRenYuanNotLike(user.getKnowRegion() + "",
							user.getShowname());
			for (JianChaRenYuan jianChaRenYuan : jianChaRenYuans) {
				dataBean.getData().getJianChaReYuans()
						.add(jianChaRenYuan.setAllowRemove(false));
			}
		}

		/**
		 * 绑定检查单位
		 */
		if (dataBean.checkJianChaDanWei() == false) {

			List<JianChaDanWei> jianChaDanWeis = db
					.queryAllJianChaDanWeiNotLike(user.getKnowRegion() + "");

			if (jianChaDanWeis.size() == 1) {
				dataBean.getData().getJianChaDanWeis()
						.add(jianChaDanWeis.get(0).setAllowRemove(false));
			}

		}

		onClickExecute.sureQuYu();
		onClickExecute.sureBeiJianDanWei();

		onClickExecute.sureTongXunDiZhi();
		onClickExecute.sureFuZeRen();
		onClickExecute.sureLianXiFangShi();

		onClickExecute.sureJianChaDanWei();
		onClickExecute.sureJianChaRenYuan();
		onClickExecute.sureJianChaHangYe();

		onClickExecute.sureJianChaJiLu();

		onClickExecute.sureNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang();
		onClickExecute.sureNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang();
		onClickExecute
				.sureNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang();
		onClickExecute
				.sureNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu();
		onClickExecute.sureNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu();

		onClickExecute.sureDuChaXunChaQiTa();

		onClickExecute.sureZhengGaiYiJian();

		onClickExecute.surePaiZhao();
		onClickExecute.sureQianMing();

	}

	/**
	 * 改变选择的图标
	 */
	private void toggleIconChange(ViewGroup viewGroup, boolean selected) {

		View ivChangeIcon = viewGroup.findViewWithTag("ivChangeIcon");

		Animation imageFadeIn = AnimationUtils.loadAnimation(getActivity(),
				R.anim.icon_anim_move_x);

		if (ivChangeIcon != null && ivChangeIcon instanceof ImageView) {

			ImageView imageView = (ImageView) ivChangeIcon;

			/**
			 * 如果是更多则切换为
			 */
			if (selected) {
				imageView.setImageResource(R.drawable.item_select);
			} else {
				imageView.setImageResource(R.drawable.jiandujiancha_icon_more);
			}
			// 加载进入

			imageView.clearAnimation();

			imageView.setAnimation(imageFadeIn);

			imageFadeIn.start();
		}

	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);

		initView();

		initConfig();
	}

	@Override
	public void onClick(View v) {

		if (v instanceof ViewGroup) {
			onClickExecute.onClick((ViewGroup) v);
		}

	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {

		// 当检查单位返回的时候
		if (requestCode == JIANCHADANWEI_REQUEST_CODE) {

			if (data != null) {
				List<JianChaDanWei> dataJianChaDanWei = (List<JianChaDanWei>) data
						.getSerializableExtra("data");

				// 清除以往数据

				dataBean.getData().getJianChaDanWeis().clear();

				dataBean.getData().setJianChaDanWeis(dataJianChaDanWei);

			}

			onClickExecute.sureJianChaDanWei();

			SerliazableUtil.saveTemp(dataBean.data, user.getUsername());
		}

		if (requestCode == JIANCHARENYUAN_REQUEST_CODE) {

			if (data != null) {

				List<JianChaRenYuan> dataJianChaRenYuans = (List<JianChaRenYuan>) data
						.getSerializableExtra("data");

				// 清除以往数据
				dataBean.getData().setJianChaReYuans(dataJianChaRenYuans);
			}

			onClickExecute.sureJianChaRenYuan();

			SerliazableUtil.saveTemp(dataBean.data, user.getUsername());

		}

		if (requestCode == PAIZHAO_REQUEST_CODE) {

			if (data != null) {

				List<Photo> photos = (List<Photo>) data.getExtras()
						.getSerializable("photos");

				if (photos != null) {
					dataBean.data.setPhotos(photos);
				}
			}

			onClickExecute.surePaiZhao();

			SerliazableUtil.saveTemp(dataBean.data, user.getUsername());

		}

		if (requestCode == QIANMING_REQUEST_CODE) {

			String qianmingpath = null;

			if (data != null) {

				qianmingpath = data.getStringExtra("qianmingpath");

			}

			dataBean.data.setQianMingPath(qianmingpath);

			onClickExecute.sureQianMing();

			SerliazableUtil.saveTemp(dataBean.data, user.getUsername());

		}

	};

	private class OnClickExecute {
		/**
		 * 确定区域,将区域信息书写到面板
		 */
		private void sureQuYu() {

			TextView tvContentDescript = (TextView) rl_jiandujiancha_item_suoshuquyu
					.findViewById(R.id.content_area);

			if (dataBean.checkQuYu()) {
				toggleIconChange(rl_jiandujiancha_item_suoshuquyu, true);

				tvContentDescript.setText(dataBean.getQuYuString());

			} else {

				toggleIconChange(rl_jiandujiancha_item_suoshuquyu, false);

				tvContentDescript.setText("");

			}

		}

		/**
		 * 确定被检单位
		 */
		private void sureBeiJianDanWei() {

			TextView tvContentDescript = (TextView) rl_jiandujiancha_item_beijiandanwei
					.findViewById(R.id.content_beijiandanwei);

			// 隐藏填写抽样单位的信息布局
			llCreateDanWeiLayout.setVisibility(View.GONE);

			if (dataBean.checkBeiJianDanWei()) {

				toggleIconChange(rl_jiandujiancha_item_beijiandanwei, true);

				tvContentDescript.setText(dataBean.data.getBeiJianDanWei()
						.getName());
				InitApplication.photolat=dataBean.data.getBeiJianDanWei().getLatitude();
				InitApplication.photolng=dataBean.data.getBeiJianDanWei().getLongitude();
				InitApplication.organization=dataBean.data.getBeiJianDanWei().getName();
				int danWeiCount = db
						.queryCountBeiJianDanWeiByName(dataBean.data
								.getBeiJianDanWei().getName(),dataBean.getKnowCode());

				if (dataBean.data.getBeiJianDanWei().isCreateShouJianDanWei()
						&& danWeiCount < 1) {
					// 隐藏填写抽样单位的信息布局
					llCreateDanWeiLayout.setVisibility(View.VISIBLE);
				} else {
					llCreateDanWeiLayout.setVisibility(View.GONE);
				}

			} else {
				toggleIconChange(rl_jiandujiancha_item_beijiandanwei, false);
				tvContentDescript.setText("");
			}

		}


		/**
		 * 确定通讯地址
		 */
		private void sureTongXunDiZhi() {

			TextView tvContentDescript = (TextView) rlAdress
					.findViewById(R.id.content_address);

			if (dataBean.checkTongXunDiZhi()) {

				toggleIconChange(rlAdress, true);

				tvContentDescript.setText(dataBean.data.getBeiJianDanWei()
						.getAddress());

			} else {
				toggleIconChange(rlAdress, false);
				tvContentDescript.setText("");
			}

		}

		/**
		 * 确认负责人
		 */
		private void sureFuZeRen() {

			TextView tvContentDescript = (TextView) rlFuZeRen
					.findViewById(R.id.contentFuZeRen);

			if (dataBean.checkFuZeRen()) {

				toggleIconChange(rlFuZeRen, true);

				tvContentDescript.setText(dataBean.data.getBeiJianDanWei()
						.getCharge());

			} else {
				toggleIconChange(rlFuZeRen, false);
				tvContentDescript.setText("");
			}

		}

		/**
		 * 确认联系方式
		 */
		private void sureLianXiFangShi() {

			TextView tvContentDescript = (TextView) rlFangShi
					.findViewById(R.id.contentPhone);

			if (dataBean.checkLianXiFangShi()) {

				toggleIconChange(rlFangShi, true);

				tvContentDescript.setText(dataBean.data.getBeiJianDanWei()
						.getMobile());

			} else {
				toggleIconChange(rlFangShi, false);
				tvContentDescript.setText("");
			}

		}

		/**
		 * 确定检查单位
		 */
		private void sureJianChaDanWei() {

			TextView tvContentDescript = (TextView) rl_jiandujiancha_item_jianchadanwei
					.findViewById(R.id.content_danwei);

			if (dataBean.checkJianChaDanWei()) {

				toggleIconChange(rl_jiandujiancha_item_jianchadanwei, true);

				tvContentDescript.setText(dataBean.getJianChaDanWeiString());
			} else {
				toggleIconChange(rl_jiandujiancha_item_jianchadanwei, false);
				tvContentDescript.setText("");

			}

		}

		/**
		 * 确定检查人员
		 */
		private void sureJianChaRenYuan() {
			TextView tvContentDescript = (TextView) rl_jiandujiancha_item_jiancharenyuan
					.findViewById(R.id.content_people);

			if (dataBean.checkJianChaRenYuan()) {
				toggleIconChange(rl_jiandujiancha_item_jiancharenyuan, true);
				tvContentDescript.setText(dataBean.getJianChaRenYuanString());

			} else {
				toggleIconChange(rl_jiandujiancha_item_jiancharenyuan, false);
				tvContentDescript.setText("");

			}
		}

		/**
		 * 确定检查行业
		 */
		private void sureJianChaHangYe() {

			TextView tvContentDescript = (TextView) rl_jiandujiancha_item_jianchahangye
					.findViewById(R.id.content_jianhangye);

			if (dataBean.checkJianChaHangYe()) {
				toggleIconChange(rl_jiandujiancha_item_jianchahangye, true);
				tvContentDescript.setText(dataBean.getJianChaHangYeString());

			} else {
				toggleIconChange(rl_jiandujiancha_item_jianchahangye, false);
				tvContentDescript.setText("");

			}

		}

		/**
		 * 确定检查记录
		 */
		private void sureJianChaJiLu() {

			TextView tvContentDescript = (TextView) rl_jiandujiancha_item_jianchajilu
					.findViewById(R.id.content_record);

			if (dataBean.checkJianChaJiLu()) {
				toggleIconChange(rl_jiandujiancha_item_jianchajilu, true);
				tvContentDescript.setText(dataBean.data.getJianChaJiLu());

			} else {
				toggleIconChange(rl_jiandujiancha_item_jianchajilu, false);
				tvContentDescript.setText("");

			}

		}

		/**
		 * 确定产地环境安全性
		 */
		private void sureNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang() {

			ViewGroup viewGroup = (ViewGroup) rlNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang
					.findViewById(R.id.ll_anQuanZeRen);

			TextView tvJieGuo = (TextView) viewGroup.getChildAt(0);

			TextView tvWenTi = (TextView) viewGroup.getChildAt(1);

			tvWenTi.setVisibility(View.GONE);

			if (dataBean.checkNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang()) {

				tvJieGuo.setVisibility(View.VISIBLE);

				toggleIconChange(
						rlNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang, true);

				JianChaJieGuo jianChaJieGuo = dataBean.data.getJianChaJieGuos()[0];

				if (jianChaJieGuo.getId() == 3) {

					tvJieGuo.setTextColor(Color.parseColor("#ffff0000"));

					tvWenTi.setTextColor(Color.parseColor("#C1C3C3"));

					if (CharsetUtil.isNotNull(jianChaJieGuo.getProblem())) {
						tvWenTi.setText(jianChaJieGuo.getProblem());

						tvWenTi.setVisibility(View.VISIBLE);
					}

				} else if (jianChaJieGuo.getId() == 2) {
					tvJieGuo.setTextColor(Color.parseColor("#F4C82D"));

				} else if (jianChaJieGuo.getId() == 1) {
					tvJieGuo.setTextColor(Color.parseColor("#32A35E"));

				}

				tvJieGuo.setText("检查结果 \u0020:\u0020" + jianChaJieGuo.getName());
			} else {

				tvJieGuo.setVisibility(View.INVISIBLE);

				toggleIconChange(
						rlNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang, false);

			}

			toggleZhengGaiYiJian();

		}

		/**
		 * 确定生产经营规范性
		 */
		private void sureNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang() {

			ViewGroup viewGroup = (ViewGroup) rlNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang
					.findViewById(R.id.ll_guiFanXing);

			TextView tvJieGuo = (TextView) viewGroup.getChildAt(0);

			TextView tvWenTi = (TextView) viewGroup.getChildAt(1);
			tvWenTi.setVisibility(View.GONE);

			if (dataBean.checkNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang()) {

				tvJieGuo.setVisibility(View.VISIBLE);

				toggleIconChange(
						rlNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang, true);

				JianChaJieGuo jianChaJieGuo = dataBean.data.getJianChaJieGuos()[1];

				if (jianChaJieGuo.getId() == 3) {

					tvJieGuo.setTextColor(Color.parseColor("#ffff0000"));

					tvWenTi.setTextColor(Color.parseColor("#C1C3C3"));

					if (CharsetUtil.isNotNull(jianChaJieGuo.getProblem())) {

						tvWenTi.setVisibility(View.VISIBLE);

						tvWenTi.setText(jianChaJieGuo.getProblem());
					}

				} else if (jianChaJieGuo.getId() == 2) {
					tvJieGuo.setTextColor(Color.parseColor("#F4C82D"));

				} else if (jianChaJieGuo.getId() == 1) {
					tvJieGuo.setTextColor(Color.parseColor("#32A35E"));

				}

				tvJieGuo.setText("检查结果 \u0020:\u0020" + jianChaJieGuo.getName());
			} else {

				tvJieGuo.setVisibility(View.INVISIBLE);

				toggleIconChange(
						rlNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang, false);

			}

			toggleZhengGaiYiJian();
		}

		/**
		 * 确定产品质量安全性
		 */
		private void sureNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang() {

			ViewGroup viewGroup = (ViewGroup) rlNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang
					.findViewById(R.id.ll_quality);

			TextView tvJieGuo = (TextView) viewGroup.getChildAt(0);

			TextView tvWenTi = (TextView) viewGroup.getChildAt(1);

			tvWenTi.setVisibility(View.GONE);

			if (dataBean
					.checkNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang()) {

				tvJieGuo.setVisibility(View.VISIBLE);

				toggleIconChange(
						rlNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang,
						true);

				JianChaJieGuo jianChaJieGuo = dataBean.data.getJianChaJieGuos()[2];

				if (jianChaJieGuo.getId() == 3) {

					tvJieGuo.setTextColor(Color.parseColor("#ffff0000"));

					tvWenTi.setTextColor(Color.parseColor("#C1C3C3"));

					if (CharsetUtil.isNotNull(jianChaJieGuo.getProblem())) {

						tvWenTi.setVisibility(View.VISIBLE);

						tvWenTi.setText(jianChaJieGuo.getProblem());
					}

				} else if (jianChaJieGuo.getId() == 2) {
					tvJieGuo.setTextColor(Color.parseColor("#F4C82D"));

				} else if (jianChaJieGuo.getId() == 1) {
					tvJieGuo.setTextColor(Color.parseColor("#32A35E"));

				}

				tvJieGuo.setText("检查结果 \u0020:\u0020" + jianChaJieGuo.getName());
			} else {

				tvJieGuo.setVisibility(View.INVISIBLE);
				toggleIconChange(
						rlNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang,
						false);

			}

			toggleZhengGaiYiJian();
		}

		/**
		 * 确定包装标识的合法性
		 */
		private void sureNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu() {

			ViewGroup viewGroup = (ViewGroup) rlNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu
					.findViewById(R.id.ll_biaoShi);

			TextView tvJieGuo = (TextView) viewGroup.getChildAt(0);

			TextView tvWenTi = (TextView) viewGroup.getChildAt(1);

			tvWenTi.setVisibility(View.GONE);

			if (dataBean
					.checkNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu()) {

				tvJieGuo.setVisibility(View.VISIBLE);

				toggleIconChange(
						rlNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu,
						true);

				JianChaJieGuo jianChaJieGuo = dataBean.data.getJianChaJieGuos()[3];

				if (jianChaJieGuo.getId() == 3) {

					tvJieGuo.setTextColor(Color.parseColor("#ffff0000"));

					tvWenTi.setTextColor(Color.parseColor("#C1C3C3"));

					if (CharsetUtil.isNotNull(jianChaJieGuo.getProblem())) {

						tvWenTi.setVisibility(View.VISIBLE);

						tvWenTi.setText(jianChaJieGuo.getProblem());
					}

				} else if (jianChaJieGuo.getId() == 2) {
					tvJieGuo.setTextColor(Color.parseColor("#F4C82D"));

				} else if (jianChaJieGuo.getId() == 1) {
					tvJieGuo.setTextColor(Color.parseColor("#32A35E"));

				}

				tvJieGuo.setText("检查结果 \u0020:\u0020" + jianChaJieGuo.getName());
			} else {

				tvJieGuo.setVisibility(View.INVISIBLE);
				toggleIconChange(
						rlNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu,
						false);

			}

			toggleZhengGaiYiJian();
		}

		/**
		 * 产品自检、监测及相关检测记录
		 */
		private void sureNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu() {

			ViewGroup viewGroup = (ViewGroup) rlNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu
					.findViewById(R.id.llRecord);

			TextView tvJieGuo = (TextView) viewGroup.getChildAt(0);

			TextView tvWenTi = (TextView) viewGroup.getChildAt(1);

			tvWenTi.setVisibility(View.GONE);

			if (dataBean.checkNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu()) {

				tvJieGuo.setVisibility(View.VISIBLE);

				toggleIconChange(
						rlNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu, true);

				JianChaJieGuo jianChaJieGuo = dataBean.data.getJianChaJieGuos()[4];

				if (jianChaJieGuo.getId() == 3) {

					tvJieGuo.setTextColor(Color.parseColor("#ffff0000"));

					tvWenTi.setTextColor(Color.parseColor("#C1C3C3"));

					if (CharsetUtil.isNotNull(jianChaJieGuo.getProblem())) {

						tvWenTi.setVisibility(View.VISIBLE);

						tvWenTi.setText(jianChaJieGuo.getProblem());
					}

				} else if (jianChaJieGuo.getId() == 2) {
					tvJieGuo.setTextColor(Color.parseColor("#F4C82D"));

				} else if (jianChaJieGuo.getId() == 1) {
					tvJieGuo.setTextColor(Color.parseColor("#32A35E"));

				}

				tvJieGuo.setText("检查结果 \u0020:\u0020" + jianChaJieGuo.getName());
			} else {

				tvJieGuo.setVisibility(View.INVISIBLE);
				toggleIconChange(
						rlNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu, false);

			}

			toggleZhengGaiYiJian();
		}

		/**
		 * 其他
		 */
		private void sureDuChaXunChaQiTa() {

			ViewGroup viewGroup = (ViewGroup) rlDuChaXunChaQiTa
					.findViewById(R.id.ll_other);

			TextView tvJieGuo = (TextView) viewGroup.getChildAt(0);

			TextView tvWenTi = (TextView) viewGroup.getChildAt(1);

			tvWenTi.setVisibility(View.GONE);

			if (dataBean.checkDuChaXunChaQiTa()) {

				tvJieGuo.setVisibility(View.VISIBLE);

				toggleIconChange(rlDuChaXunChaQiTa, true);

				JianChaJieGuo jianChaJieGuo = dataBean.data.getJianChaJieGuos()[5];

				if (jianChaJieGuo.getId() == 3) {

					tvJieGuo.setTextColor(Color.parseColor("#ffff0000"));

					tvWenTi.setTextColor(Color.parseColor("#C1C3C3"));

					if (CharsetUtil.isNotNull(jianChaJieGuo.getProblem())) {

						tvWenTi.setVisibility(View.VISIBLE);

						tvWenTi.setText(jianChaJieGuo.getProblem());
					}

				} else if (jianChaJieGuo.getId() == 2) {
					tvJieGuo.setTextColor(Color.parseColor("#F4C82D"));

				} else if (jianChaJieGuo.getId() == 1) {
					tvJieGuo.setTextColor(Color.parseColor("#32A35E"));

				}

				tvJieGuo.setText("检查结果 \u0020:\u0020" + jianChaJieGuo.getName());
			} else {

				tvJieGuo.setVisibility(View.INVISIBLE);
				toggleIconChange(rlDuChaXunChaQiTa, false);

			}

			toggleZhengGaiYiJian();
		}

		/**
		 * 确认整改意见
		 */
		private void sureZhengGaiYiJian() {

			TextView tvJianGuanNeiRong = (TextView) rlZhengGaiYiJianItemLayout
					.findViewById(R.id.llSuggest);

			if (dataBean.checkZhengGaiYiJian()) {

				tvJianGuanNeiRong.setText(dataBean.data.getZhengGaiYiJian());

				toggleIconChange(rlZhengGaiYiJianItemLayout, true);

			} else {

				toggleIconChange(rlZhengGaiYiJianItemLayout, false);
				tvJianGuanNeiRong.setText("");

			}

		}

		/**
		 * �_定拍照
		 */
		private void surePaiZhao() {

			ViewGroup photoLayout = (ViewGroup) rl_jiandujiancha_item_paizhao
					.findViewById(R.id.llPhoto);

			photoLayout.setVisibility(View.INVISIBLE);

			if (dataBean.checkPaiZhao()) {

				toggleIconChange(rl_jiandujiancha_item_paizhao, true);

				photoLayout.removeAllViews();

				photoLayout.setVisibility(View.VISIBLE);

				List<Photo> photos = dataBean.data.getUploadPhoto();

				for (int i = 0; i < photos.size(); i++) {

					Photo photo = photos.get(i);

					// 最多放5个图片
					if (i > 5) {
						break;
					}

					ImageView imageView = new ImageView(getActivity());

					imageView.setClickable(false);

					if (i == 0) {

						int widthOrHeight = Utils.dip2px(getActivity(), 50);

						int marginLeft = Utils.dip2px(getActivity(), 8);

						MarginLayoutParams rootLayoutPrams = new MarginLayoutParams(
								widthOrHeight, widthOrHeight);

						rootLayoutPrams.setMargins(marginLeft, 0, 0, 0);

						// 兼容低版本设置margin方法
						LayoutParams layoutPrarams = new LayoutParams(
								rootLayoutPrams);
						layoutPrarams.gravity = Gravity.TOP | Gravity.LEFT;

						imageView.setLayoutParams(layoutPrarams);
						imageView.setScaleType(ScaleType.CENTER_CROP);
					} else {

						int widthOrHeight = Utils.dip2px(getActivity(), 50);

						int marginLeft = Utils.dip2px(getActivity(), 15);

						MarginLayoutParams rootLayoutPrams = new MarginLayoutParams(
								widthOrHeight, widthOrHeight);

						rootLayoutPrams.setMargins(marginLeft, 0, 0, 0);

						// 兼容低版本设置margin方法
						LayoutParams layoutPrarams = new LayoutParams(
								rootLayoutPrams);
						layoutPrarams.gravity = Gravity.TOP | Gravity.LEFT;

						imageView.setLayoutParams(layoutPrarams);

						imageView.setScaleType(ScaleType.CENTER_CROP);

					}

					BitmapFactory.Options opts = new BitmapFactory.Options();
					opts.inSampleSize = 2;

					Bitmap image = BitmapFactory.decodeFile(
							(String) photo.getSmallPhotoPath(), opts);

					if (photo.getSmallPhotoPath() instanceof String) {
						imageView.setImageBitmap(image);

					}

					photoLayout.addView(imageView);

				}

			} else {
				toggleIconChange(rl_jiandujiancha_item_paizhao, false);
			}

		}

		/**
		 * 确定签名
		 */
		private void sureQianMing() {

			ImageView ivSmallImage = (ImageView) rl_jiandujiancha_item_qianming
					.findViewById(R.id.qianMingSmallImage);

			if (dataBean.checkQianMing()) {

				BitmapFactory.Options options = new BitmapFactory.Options();

				options.inSampleSize = 2;

				Bitmap smallImage = BitmapFactory.decodeFile(
						dataBean.data.getQianMingPath(), options);

				if (smallImage != null) {
					ivSmallImage.setImageBitmap(smallImage);
					toggleIconChange(rl_jiandujiancha_item_qianming, true);
				}

			} else {
				// 清空图片.
				ivSmallImage.setImageBitmap(null);
				toggleIconChange(rl_jiandujiancha_item_qianming, false);

			}

		}

		/**
		 * 点击事件的处理方法
		 *
		 * @param viewGroup
		 * @param fromSystem
		 */
		private void onClick(ViewGroup viewGroup) {

			final AlertDialog bottomWindow = new AlertDialog.Builder(
					new ContextThemeWrapper(getActivity(),
							R.style.NongYeTongFullscreenTheme)).create();

			// 输入法的设置
			bottomWindow.getWindow().setFlags(
					WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
					WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

			// 设置窗口的动画
			bottomWindow.getWindow().setWindowAnimations(
					R.style.bottomAnimStyle);

			if (viewGroup == rl_jiandujiancha_item_suoshuquyu) {
				ViewGroup bottomXuanZeQuYuWindowLayout = (ViewGroup) LayoutInflater
						.from(getActivity()).inflate(
								R.layout.bottom_suanshuquyu, null);

				bottomWindow.show();

				// 让底部的宽度和屏幕的宽度一致
				bottomXuanZeQuYuWindowLayout.setMinimumWidth(getActivity()
						.getWindowManager().getDefaultDisplay().getWidth());

				// 设置底部布局
				bottomWindow.setContentView(bottomXuanZeQuYuWindowLayout);

				// 弹出输入法的操作
				bottomWindow.getWindow().clearFlags(
						WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

				// 设置到底部
				bottomWindow.getWindow().setGravity(Gravity.BOTTOM);

				/**
				 * 加载所选区域的三个WheelView
				 */
				final WheelView wvCity = (WheelView) bottomXuanZeQuYuWindowLayout
						.findViewById(R.id.wdCity);

				WheelViewAdapter adpCity = new WheelViewAdapter(getActivity());

				/**
				 * 增加市的数据,根据用户信息查询单个
				 */
				List<Town> citys = new ArrayList<Town>();

				ArrayList<TextInfo> wvCityDatas = new ArrayList<TextInfo>();

				citys.add(dataBean.getData().getTowns()[0]);

				wvCity.setEnabled(false);

				for (Town town : citys) {

					if (town != null) {
						// 添加市的数据
						wvCityDatas.add(new TextInfo(town.getCode(), town
								.getName(), town));
					}

				}

				adpCity.setData(wvCityDatas);

				wvCity.setAdapter(adpCity);

				/**
				 * 加载所选区域的三个WheelView
				 */
				final WheelView wvArea = (WheelView) bottomXuanZeQuYuWindowLayout
						.findViewById(R.id.wdArea);

				WheelViewAdapter adpArea = new WheelViewAdapter(getActivity());

				/**
				 * 增加区域的数据,根据用户信息查询单个
				 */
				List<Town> areas = db.queryTownByParent(dataBean.getData()
						.getTowns()[0].getCode());

				final ArrayList<TextInfo> wvAreaDatas = new ArrayList<TextInfo>();

				if (dataBean.getData().getTowns()[1] != null
						&& user.getArea() != null) {
					wvArea.setEnabled(false);
				} else {
					wvAreaDatas.add(new TextInfo(-1, "[请选择]", null));

				}

				for (Town town : areas) {
					// 添加市的数据
					wvAreaDatas.add(new TextInfo(town.getCode(),
							town.getName(), town));
				}

				adpArea.setData(wvAreaDatas);

				wvArea.setAdapter(adpArea);

				TextInfo areaFilter = null;

				if (dataBean.getData().getTowns()[1] != null) {

					areaFilter = new TextInfo(
							dataBean.getData().getTowns()[1].getCode(), null);
				} else {
					areaFilter = new TextInfo(null, null);
				}

				int position = wvAreaDatas.indexOf(areaFilter);

				position = position < 0 ? 0 : position;

				wvArea.setSelection(position);

				/**
				 * 加载所选区域的三个WheelView
				 */
				final WheelView wvTown = (WheelView) bottomXuanZeQuYuWindowLayout
						.findViewById(R.id.wdTown);

				final WheelViewAdapter adpTown = new WheelViewAdapter(
						getActivity());

				TextInfo areaInfo = (TextInfo) wvArea.getSelectedItem();

				/**
				 * 增加乡镇的数据
				 */
				List<Town> towns = db.queryTownByParent("" + areaInfo.id);

				final ArrayList<TextInfo> wvTownDatas = new ArrayList<TextInfo>();

				if (dataBean.getData().getTowns()[2] != null
						&& user.getTownId() != null) {
					wvTown.setEnabled(false);
				} else {
					wvTownDatas.add(new TextInfo(-1, "[请选择]", null));
				}

				for (Town town : towns) {

					// 添加市的数据
					wvTownDatas.add(new TextInfo(town.getCode(),
							town.getName(), town));

				}

				adpTown.setData(wvTownDatas);

				wvTown.setAdapter(adpTown);

				if (dataBean.getData().getTowns()[2] == null) {
					wvTown.setSelection(0);
				} else {

					TextInfo townFilter = new TextInfo(dataBean.getData()
							.getTowns()[2].getCode(), null);

					position = wvTownDatas.indexOf(townFilter);

					wvTown.setSelection(position);
				}

				wvArea.setOnItemSelectedListener(new OnItemSelectedListener() {

					@Override
					public void onItemSelected(TosAdapterView<?> parent,
											   View view, int position, long id) {

						TextInfo textInfo = wvAreaDatas.get(position);

						wvTownDatas.clear();

						/**
						 * 增加乡镇的数据
						 */
						List<Town> towns = db.queryTownByParent(textInfo.id
								+ "");

						wvTownDatas.add(0, new TextInfo(-1, "[请选择]", null));

						for (Town town : towns) {

							// 添加市的数据
							wvTownDatas.add(new TextInfo(town.getCode(), town
									.getName(), town));

						}

						adpTown.notifyDataSetChanged();

						if (wvTownDatas.size() > 1) {

							wvTown.setSelection(1);
						}

					}

					@Override
					public void onNothingSelected(TosAdapterView<?> parent) {
					}
				});

				// 底部Window 的返回按钮
				ViewGroup btnBottomBack = (ViewGroup) bottomXuanZeQuYuWindowLayout
						.findViewById(R.id.btnBack);

				ViewGroup btnSureXuanZeQuYu = (ViewGroup) bottomXuanZeQuYuWindowLayout
						.findViewById(R.id.btnSureXuanZeQuYu);

				btnBottomBack.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						bottomWindow.dismiss();
					}
				});

				btnSureXuanZeQuYu.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						TextInfo cityTextInfo = (TextInfo) wvCity
								.getSelectedItem();

						if (cityTextInfo.data instanceof Town) {

							dataBean.getData().getTowns()[0] = (Town) cityTextInfo.data;

						} else {
							dataBean.getData().getTowns()[0] = null;

						}

						TextInfo areaTextInfo = (TextInfo) wvArea
								.getSelectedItem();

						if (areaTextInfo.data instanceof Town) {

							dataBean.getData().getTowns()[1] = (Town) areaTextInfo.data;

						} else {
							dataBean.getData().getTowns()[1] = null;
						}

						TextInfo townTextInfo = (TextInfo) wvTown
								.getSelectedItem();

						if (townTextInfo.data instanceof Town) {
							dataBean.getData().getTowns()[2] = (Town) townTextInfo.data;
						} else {
							dataBean.getData().getTowns()[2] = null;
						}

						sureQuYu();

						dataBean.data.setBeiJianDanWei(null);

						sureBeiJianDanWei();

						SerliazableUtil.saveTemp(dataBean.data,
								user.getUsername());

						bottomWindow.dismiss();
					}
				});

			}

			/**
			 * 当点击被检单位
			 */
			if (viewGroup == rl_jiandujiancha_item_beijiandanwei) {

				bottomWindow.show();

				// 让底部的宽度和屏幕的宽度一致
				ViewGroup bottomBeiJianDanWeiWindowLayout = (ViewGroup) getActivity()
						.getLayoutInflater().inflate(
								R.layout.bottom_beijiandanwei, null);

				bottomBeiJianDanWeiWindowLayout.setMinimumWidth(getActivity()
						.getWindowManager().getDefaultDisplay().getWidth());

				// 设置底部布局
				bottomWindow.setContentView(bottomBeiJianDanWeiWindowLayout);

				// 弹出输入法的操作
				bottomWindow.getWindow().clearFlags(
						WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

				bottomWindow.getWindow().setGravity(Gravity.BOTTOM);

				/**
				 * 加载被检单位
				 */
				final WheelView wvBeiJianDanWei = (WheelView) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.wvBeiJianDanWei);

				final WheelViewAdapter adpBeiJianDanWeiAdapter = new WheelViewAdapter(
						getActivity());

				wvBeiJianDanWei.setAdapter(adpBeiJianDanWeiAdapter);

				ViewGroup btnBottomBack = (ViewGroup) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.btnBack);

				btnBottomBack.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						bottomWindow.dismiss();
					}
				});

				ViewGroup beiJianDanWeiBommtomSure = (ViewGroup) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.btnSure);

				beiJianDanWeiBommtomSure
						.setOnClickListener(new OnClickListener() {

							@Override
							public void onClick(View v) {

								TextInfo textInfo = (TextInfo) wvBeiJianDanWei
										.getSelectedItem();

								if (textInfo != null && textInfo.data != null) {

									dataBean.getData().setBeiJianDanWei(
											(BeiJianDanWei) textInfo.data);

								} else {
									dataBean.getData().setBeiJianDanWei(null);
								}

								// if (!dataBean.checkTongXunDiZhi()
								// || !dataBean.checkFuZeRen()
								// || !dataBean.checkLianXiFangShi()) {

								int danWeiCount = db
										.queryCountBeiJianDanWeiByName(dataBean.data
												.getBeiJianDanWei().getName(),dataBean.getKnowCode());

								// 如果受检单位不存在
								if (danWeiCount < 1) {

									final CustomDialog createShouJianDanWeiDialog = new CustomDialog(
											getActivity());

									createShouJianDanWeiDialog
											.setHeightPercent(0.4f);

									createShouJianDanWeiDialog
											.setOnActionClickListener(new OnClickListener() {

												@Override
												public void onClick(View v) {

													dataBean.data
															.getBeiJianDanWei()
															.setAddress(null);
													dataBean.data
															.getBeiJianDanWei()
															.setCharge(null);

													dataBean.data
															.getBeiJianDanWei()
															.setMobile(null);

													createShouJianDanWeiDialog
															.dismiss();

													dataBean.data
															.getBeiJianDanWei()
															.setCreateShouJianDanWei(
																	false);

													SerliazableUtil.saveTemp(
															dataBean.data,
															user.getUsername());

													// 是否创建的状态改变,重新确定布局
													sureBeiJianDanWei();

													sureTongXunDiZhi();

													sureFuZeRen();

													sureLianXiFangShi();

												}
											});

									createShouJianDanWeiDialog
											.setOnCancleClickListener(new OnClickListener() {

												@Override
												public void onClick(View v) {

													// Q定要创建不显示其他的详细填写信息

													dataBean.data
															.getBeiJianDanWei()
															.setCreateShouJianDanWei(
																	true);

													SerliazableUtil.saveTemp(
															dataBean.data,
															user.getUsername());

													// dataBean.data
													// .getBeiJianDanWei()
													// .setAddress(null);
													// dataBean.data
													// .getBeiJianDanWei()
													// .setCharge(null);
													//
													// dataBean.data
													// .getBeiJianDanWei()
													// .setMobile(null);

													createShouJianDanWeiDialog
															.dismiss();

													// 是否创建的状态改变,重新确定布局
													sureBeiJianDanWei();

													sureTongXunDiZhi();

													sureFuZeRen();

													sureLianXiFangShi();

												}
											});

									createShouJianDanWeiDialog
											.setNote("是，在监管平台中自动创建一个当前名称的监管对象，稍后请到监管平台网上补全资料；\n否，则该单位不会作为被监管的对象，不出现在监管平台的监管对象中。");

									createShouJianDanWeiDialog
											.setCancleTxt("是");

									createShouJianDanWeiDialog
											.setActionTxt("否");

									createShouJianDanWeiDialog
											.setMessage("受检对象不存在,是否创建？");

									createShouJianDanWeiDialog.show();

								} else {
									dataBean.data.getBeiJianDanWei()
											.setCreateShouJianDanWei(false);

								}
								// }

								// 是否创建的状态改变,重新确定布局
								sureBeiJianDanWei();

								SerliazableUtil.saveTemp(dataBean.data,
										user.getUsername());

								bottomWindow.dismiss();
							}
						});

				// 检查单位根据名字进行过滤
				final EditText etBeiJianDanWeiFilter = (EditText) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.etBeiJianDanWeiFilter);

				TextWatcher textWatcher = new TextWatcher() {

					@Override
					public void onTextChanged(CharSequence s, int start,
											  int before, int count) {

					}

					@Override
					public void beforeTextChanged(CharSequence s, int start,
												  int count, int after) {

					}

					@Override
					public void afterTextChanged(Editable s) {

						String filter = s.toString().trim();

						List<BeiJianDanWei> beiJianDanWeis = null;

						if (CharsetUtil.isNotNull(filter)) {
							beiJianDanWeis = db.queryAllBeiJianDanWie(filter,
									dataBean.getKnowCode() + "");
							if (beiJianDanWeis.size() < 1) {

								beiJianDanWeis.add(new BeiJianDanWei("0",
										filter));

							}
						} else {
							beiJianDanWeis = db.queryAllBeiJianDanWie(dataBean
									.getKnowCode() + "");
						}

						ArrayList<TextInfo> wvBeiJianDanWeiDatas = new ArrayList<TextInfo>();

						for (BeiJianDanWei beiJianDanWei : beiJianDanWeis) {

							TextInfo textInfo = new TextInfo(
									beiJianDanWei.getId(),
									beiJianDanWei.getName(), beiJianDanWei);

							wvBeiJianDanWeiDatas.add(textInfo);
						}

						adpBeiJianDanWeiAdapter.setData(wvBeiJianDanWeiDatas);

					}
				};

				etBeiJianDanWeiFilter.addTextChangedListener(textWatcher);

				// 当开始的时候传递空的进去
				textWatcher.afterTextChanged(new SpannableStringBuilder(""));

				if (dataBean.getData().getBeiJianDanWei() != null) {

					TextInfo textInfo = new TextInfo(dataBean.getData()
							.getBeiJianDanWei().getId(), dataBean.getData()
							.getBeiJianDanWei().getName());

					int position = adpBeiJianDanWeiAdapter
							.getPosition(textInfo);

					if (position > -1) {
						wvBeiJianDanWei.setSelection(position);
					} else {
						etBeiJianDanWeiFilter.setText(dataBean.getData()
								.getBeiJianDanWei().getName());

						textWatcher
								.afterTextChanged(new SpannableStringBuilder(
										dataBean.getData().getBeiJianDanWei()
												.getName()));
					}

				}

			}

			/**
			 * 点击通讯地址
			 */
			if (rlAdress == viewGroup) {

				bottomWindow.show();

				// 让底部的宽度和屏幕的宽度一致
				ViewGroup bottomBeiJianDanWeiWindowLayout = (ViewGroup) getActivity()
						.getLayoutInflater().inflate(
								R.layout.bottom_photodetail_comment, null);

				bottomBeiJianDanWeiWindowLayout.setMinimumWidth(getActivity()
						.getWindowManager().getDefaultDisplay().getWidth());

				// 设置底部布局
				bottomWindow.setContentView(bottomBeiJianDanWeiWindowLayout);

				// 弹出输入法的操作
				bottomWindow.getWindow().clearFlags(
						WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

				bottomWindow.getWindow().setGravity(Gravity.BOTTOM);

				TextView tvTitle = (TextView) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.tvTitle);

				tvTitle.setText(getString(R.string.chanpinjiance_txdz_title));

				final TextView edtContent = (TextView) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.edtCommentPhoto);

				edtContent.setHint("请输入通讯地址");

				// 数据还原
				if (dataBean.checkTongXunDiZhi()) {
					edtContent.setText(dataBean.data.getBeiJianDanWei()
							.getAddress());
				}

				// 设置最多30个字符
				edtContent
						.setFilters(new InputFilter[] { new InputFilter.LengthFilter(
								30) });

				ViewGroup btnBack = (ViewGroup) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.btnBack);

				btnBack.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						bottomWindow.dismiss();
					}
				});

				ViewGroup btnSure = (ViewGroup) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.btnSure);

				btnSure.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						String address = edtContent.getText().toString().trim();

						if (!CharsetUtil.isNotNull(address)) {

							Toast.makeText(getActivity(), "请输入通讯地址...",
									Toast.LENGTH_SHORT).show();

							return;
						}

						// 设置通讯地址
						dataBean.data.getBeiJianDanWei().setAddress(address);

						sureTongXunDiZhi();

						SerliazableUtil.saveTemp(dataBean.data,
								user.getUsername());

						bottomWindow.dismiss();
					}
				});

			}

			/**
			 * 点击负责人的时候
			 */
			if (rlFuZeRen == viewGroup) {

				bottomWindow.show();

				// 让底部的宽度和屏幕的宽度一致
				ViewGroup bottomBeiJianDanWeiWindowLayout = (ViewGroup) getActivity()
						.getLayoutInflater().inflate(
								R.layout.bottom_photodetail_comment, null);

				bottomBeiJianDanWeiWindowLayout.setMinimumWidth(getActivity()
						.getWindowManager().getDefaultDisplay().getWidth());

				// 设置底部布局
				bottomWindow.setContentView(bottomBeiJianDanWeiWindowLayout);

				// 弹出输入法的操作
				bottomWindow.getWindow().clearFlags(
						WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

				bottomWindow.getWindow().setGravity(Gravity.BOTTOM);

				TextView tvTitle = (TextView) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.tvTitle);

				tvTitle.setText(getString(R.string.chanpinjiance_fzr_title));

				final TextView edtContent = (TextView) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.edtCommentPhoto);

				edtContent.setHint("请输入负责人姓名");

				// 数据还原
				if (dataBean.checkFuZeRen()) {
					edtContent.setText(dataBean.data.getBeiJianDanWei()
							.getCharge());
				}

				// 设置最多30个字符
				edtContent
						.setFilters(new InputFilter[] { new InputFilter.LengthFilter(
								6) });

				ViewGroup btnBack = (ViewGroup) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.btnBack);

				btnBack.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						bottomWindow.dismiss();
					}
				});

				ViewGroup btnSure = (ViewGroup) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.btnSure);

				btnSure.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						String charge = edtContent.getText().toString().trim();

						if (!CharsetUtil.isNotNull(charge)) {

							Toast.makeText(getActivity(), "请输入负责人姓名...",
									Toast.LENGTH_SHORT).show();

							return;
						}

						if (charge.length() > 4) {

							Toast.makeText(getActivity(), "输入负责人姓名非法...超过了4个字",
									Toast.LENGTH_SHORT).show();

							return;
						}

						// 设置通讯地址
						dataBean.data.getBeiJianDanWei().setCharge(charge);

						sureFuZeRen();

						SerliazableUtil.saveTemp(dataBean.data,
								user.getUsername());

						bottomWindow.dismiss();
					}
				});

			}

			/**
			 * 点击联系方式
			 */
			if (rlFangShi == viewGroup) {

				bottomWindow.show();

				// 让底部的宽度和屏幕的宽度一致
				ViewGroup bottomBeiJianDanWeiWindowLayout = (ViewGroup) getActivity()
						.getLayoutInflater().inflate(
								R.layout.bottom_photodetail_comment, null);

				bottomBeiJianDanWeiWindowLayout.setMinimumWidth(getActivity()
						.getWindowManager().getDefaultDisplay().getWidth());

				// 设置底部布局
				bottomWindow.setContentView(bottomBeiJianDanWeiWindowLayout);

				// 弹出输入法的操作
				bottomWindow.getWindow().clearFlags(
						WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

				bottomWindow.getWindow().setGravity(Gravity.BOTTOM);

				TextView tvTitle = (TextView) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.tvTitle);

				tvTitle.setText(getString(R.string.chanpinjiance_lxfs_title));

				final TextView edtContent = (TextView) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.edtCommentPhoto);

				edtContent.setHint("请输入联系人的手机或座机号码");

				// 数据还原
				if (dataBean.checkLianXiFangShi()) {
					edtContent.setText(dataBean.data.getBeiJianDanWei()
							.getMobile());
				}

				// 设置只允许输入号码
				edtContent.setInputType(InputType.TYPE_CLASS_PHONE);

				int minHeight = Utils.dip2px(getActivity(), 150);

				edtContent.setMinHeight(minHeight);

				// 设置最多输入的字符个数
				edtContent
						.setFilters(new InputFilter[] { new InputFilter.LengthFilter(
								13) });

				ViewGroup btnBack = (ViewGroup) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.btnBack);

				btnBack.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						bottomWindow.dismiss();
					}
				});

				ViewGroup btnSure = (ViewGroup) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.btnSure);

				btnSure.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						String mobile = edtContent.getText().toString().trim();

						if (!CharsetUtil.isNotNull(mobile)) {

							Toast.makeText(getActivity(), "请输入号码...",
									Toast.LENGTH_SHORT).show();

							return;
						}

						if (!CharsetUtil.checkPhone(mobile)) {
							Toast.makeText(getActivity(), "输入号码的号码格式错误...",
									Toast.LENGTH_SHORT).show();

							return;
						}

						// 设置通讯地址
						dataBean.data.getBeiJianDanWei().setMobile(mobile);

						sureLianXiFangShi();

						SerliazableUtil.saveTemp(dataBean.data,
								user.getUsername());

						bottomWindow.dismiss();
					}
				});

			}

			if (viewGroup == rl_jiandujiancha_item_jianchadanwei) {

				Intent to_jianchadanwei_intent = new Intent(getActivity(),
						ListViewCheckManagerActivity.class);

				if (dataBean.getData().getJianChaDanWeis().size() > 0) {
					to_jianchadanwei_intent.putExtra("data",
							(Serializable) dataBean.getData()
									.getJianChaDanWeis());
				}

				to_jianchadanwei_intent.putExtra("user", user);

				to_jianchadanwei_intent.putExtra("title", "检查单位");

				to_jianchadanwei_intent.putExtra("type", "danwei");

				startActivityForResult(to_jianchadanwei_intent,
						JIANCHADANWEI_REQUEST_CODE);

			}

			if (viewGroup == rl_jiandujiancha_item_jiancharenyuan) {

				Intent to_jianrenyuan_intent = new Intent(getActivity(),
						ListViewCheckManagerActivity.class);

				if (dataBean.getData().getJianChaReYuans().size() > 0) {

					to_jianrenyuan_intent.putExtra("dataJianChaRenYuan",
							(Serializable) dataBean.getData()
									.getJianChaReYuans());
				}

				to_jianrenyuan_intent.putExtra("code", user.getKnowRegion()
						+ "");

				to_jianrenyuan_intent.putExtra("type", "jiancharenyuan");

				to_jianrenyuan_intent.putExtra("user", user);

				to_jianrenyuan_intent.putExtra("data", (ArrayList) dataBean
						.getData().getJianChaReYuans());

				to_jianrenyuan_intent.putExtra("title", "检查人员");

				startActivityForResult(to_jianrenyuan_intent,
						JIANCHARENYUAN_REQUEST_CODE);

			}

			// 当点击检查行业的时候
			if (viewGroup == rl_jiandujiancha_item_jianchahangye) {

				bottomWindow.show();

				/**
				 * 检查行业底部的布局
				 */
				ViewGroup bottomJianChaHangYeWindowLayout = (ViewGroup) getActivity()
						.getLayoutInflater().inflate(
								R.layout.bottom_jianchahangye, null);

				// 让底部的宽度和屏幕的宽度一致
				bottomJianChaHangYeWindowLayout.setMinimumWidth(getActivity()
						.getWindowManager().getDefaultDisplay().getWidth());

				// 设置底部布局
				bottomWindow.setContentView(bottomJianChaHangYeWindowLayout);

				// 弹出输入法的操作
				bottomWindow.getWindow().clearFlags(
						WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

				bottomWindow.getWindow().setGravity(Gravity.BOTTOM);

				/**
				 * 进行视图的动态生成
				 */
				ViewGroup jianChaHangYeLayout = (ViewGroup) bottomJianChaHangYeWindowLayout
						.findViewById(R.id.jianchayangyelayout);
				// 清理视图
				jianChaHangYeLayout.removeAllViews();

				// 查询出所有检查行业
				List<JianChaHangYe> jianChaHangYes = db.queryAllJianChaHangYe();

				final List<CheckBox> cbsJianChaHangYe = new ArrayList<CheckBox>();

				// 遍历检查行业进行视图的生成
				for (final JianChaHangYe temp : jianChaHangYes) {

					if (temp.getName().equals("渔业")) {
						continue;
					}

					final RelativeLayout rootLayout = new RelativeLayout(
							getActivity());

					MarginLayoutParams rootLayoutPrams = new MarginLayoutParams(
							MarginLayoutParams.MATCH_PARENT,
							MarginLayoutParams.WRAP_CONTENT);

					rootLayoutPrams.setMargins(0,
							Utils.dip2px(getActivity(), 3), 0,
							Utils.dip2px(getActivity(), 3));

					// 兼容低版本设置margin方法
					LayoutParams layoutPrarams = new LayoutParams(
							rootLayoutPrams);
					layoutPrarams.gravity = Gravity.TOP | Gravity.LEFT;

					rootLayout.setLayoutParams(layoutPrarams);
					rootLayout.setClickable(true);
					rootLayout.setGravity(Gravity.CENTER_VERTICAL);
					rootLayout.setPadding(Utils.dip2px(getActivity(), 8),
							Utils.dip2px(getActivity(), 5),
							Utils.dip2px(getActivity(), 8),
							Utils.dip2px(getActivity(), 5));
					rootLayout
							.setBackgroundResource(R.drawable.jiandujiancha_item_style);

					/*********************************************/
					TextView tvBeiJianChaHangYe = new TextView(getActivity());

					RelativeLayout.LayoutParams tvBeiJianChaHangYeLayout = new RelativeLayout.LayoutParams(
							RelativeLayout.LayoutParams.WRAP_CONTENT,
							RelativeLayout.LayoutParams.WRAP_CONTENT);
					tvBeiJianChaHangYeLayout
							.addRule(RelativeLayout.CENTER_VERTICAL);
					tvBeiJianChaHangYe
							.setLayoutParams(tvBeiJianChaHangYeLayout);

					tvBeiJianChaHangYe.setPadding(
							Utils.dip2px(getActivity(), 8),
							Utils.dip2px(getActivity(), 8),
							Utils.dip2px(getActivity(), 8),
							Utils.dip2px(getActivity(), 8));
					tvBeiJianChaHangYe
							.setTextColor(Color.parseColor("#656769"));
					tvBeiJianChaHangYe.setTextSize(20);
					tvBeiJianChaHangYe.setText(temp.getName());

					rootLayout.addView(tvBeiJianChaHangYe);

					/*********************************************/

					CheckBox cbBeiJianChaHangYe = new CheckBox(getActivity());

					cbBeiJianChaHangYe.setTag(temp);

					RelativeLayout.LayoutParams cbBeiJianChaHangYeLayout = new RelativeLayout.LayoutParams(
							RelativeLayout.LayoutParams.WRAP_CONTENT,
							RelativeLayout.LayoutParams.WRAP_CONTENT);
					cbBeiJianChaHangYeLayout
							.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
					cbBeiJianChaHangYeLayout
							.addRule(RelativeLayout.CENTER_VERTICAL);
					cbBeiJianChaHangYe
							.setLayoutParams(cbBeiJianChaHangYeLayout);

					if (dataBean.data.getJianChaHangYes().contains(temp)) {
						cbBeiJianChaHangYe.setChecked(true);

					} else {

						cbBeiJianChaHangYe.setChecked(false);
					}

					cbBeiJianChaHangYe
							.setButtonDrawable(R.drawable.checkbox_select_style);

					rootLayout.addView(cbBeiJianChaHangYe);

					rootLayout.setTag(cbBeiJianChaHangYe);

					// 增加到缓存集合中
					cbsJianChaHangYe.add(cbBeiJianChaHangYe);

					jianChaHangYeLayout.addView(rootLayout);

					// 绑定事件,当布局被点击的时候选中checkbox
					rootLayout.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {

							if (rootLayout.getTag() instanceof CheckBox) {

								CheckBox cbsJianChaHangYe = (CheckBox) rootLayout
										.getTag();

								// 将指定项选中
								if (cbsJianChaHangYe.isChecked()) {
									cbsJianChaHangYe.setChecked(false);
								} else {
									cbsJianChaHangYe.setChecked(true);
								}

							}

						}
					});

				}

				// 底部Window 的返回按钮
				ViewGroup btnBottomBack = (ViewGroup) bottomJianChaHangYeWindowLayout
						.findViewById(R.id.btnBack);

				btnBottomBack.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						bottomWindow.dismiss();
					}
				});

				// 选择区域底部的确定按钮
				ViewGroup btnSureJianChaHangYe = (ViewGroup) bottomJianChaHangYeWindowLayout
						.findViewById(R.id.btnSureJianChaHangYe);

				btnSureJianChaHangYe.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						dataBean.data.getJianChaHangYes().clear();

						for (CheckBox checkBox : cbsJianChaHangYe) {

							if (checkBox.getTag() instanceof JianChaHangYe
									&& checkBox.isChecked()) {

								JianChaHangYe hangYe = (JianChaHangYe) checkBox
										.getTag();

								dataBean.data.getJianChaHangYes().add(hangYe);
							}

						}

						sureJianChaHangYe();

						SerliazableUtil.saveTemp(dataBean.data,
								user.getUsername());

						bottomWindow.dismiss();

					}
				});

			}

			// rl_jiandujiancha_item_jianchajilu

			/*
			 * 点击检查记录
			 */
			if (viewGroup == rl_jiandujiancha_item_jianchajilu) {

				bottomWindow.show();

				// 让底部的宽度和屏幕的宽度一致
				ViewGroup bottomBeiJianDanWeiWindowLayout = (ViewGroup) getActivity()
						.getLayoutInflater().inflate(
								R.layout.bottom_photodetail_comment, null);

				bottomBeiJianDanWeiWindowLayout.setMinimumWidth(getActivity()
						.getWindowManager().getDefaultDisplay().getWidth());

				// 设置底部布局
				bottomWindow.setContentView(bottomBeiJianDanWeiWindowLayout);

				// 弹出输入法的操作
				bottomWindow.getWindow().clearFlags(
						WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

				bottomWindow.getWindow().setGravity(Gravity.BOTTOM);

				TextView tvTitle = (TextView) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.tvTitle);

				tvTitle.setText(getString(R.string.jiandujiancha_item_jianchajilu));

				final TextView edtContent = (TextView) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.edtCommentPhoto);

				edtContent
						.setHint(getString(R.string.jiandujiancha_item_jianchaneirong_jianchajilu_hint));

				if (dataBean.checkJianChaJiLu()) {

					edtContent.setText(dataBean.data.getJianChaJiLu());

				}

				ViewGroup btnBack = (ViewGroup) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.btnBack);

				ViewGroup btnSure = (ViewGroup) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.btnSure);

				btnSure = (ViewGroup) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.btnSure);

				btnSure.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						String jianChaJiLu = edtContent.getText().toString()
								.trim();

						dataBean.data.setJianChaJiLu(jianChaJiLu);

						sureJianChaJiLu();

						SerliazableUtil.saveTemp(dataBean.data,
								user.getUsername());

						bottomWindow.dismiss();

					}
				});

				btnBack.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						bottomWindow.dismiss();

					}
				});

			}

			/**
			 * 点击产地环境安全性
			 */
			if (viewGroup == rlNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang
					|| viewGroup == rlNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang
					|| viewGroup == rlNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang
					|| viewGroup == rlNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu
					|| viewGroup == rlNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu
					|| viewGroup == rlDuChaXunChaQiTa) {

				ViewGroup buttomJianChaNeiRongItemLayout = (ViewGroup) getActivity()
						.getLayoutInflater().inflate(
								R.layout.bottom_beijianneirong_richangjianguan,
								null);

				bottomWindow.show();

				// 让底部的宽度和屏幕的宽度一致
				buttomJianChaNeiRongItemLayout.setMinimumWidth(getActivity()
						.getWindowManager().getDefaultDisplay().getWidth());

				// 设置底部布局
				bottomWindow.setContentView(buttomJianChaNeiRongItemLayout);

				// 弹出输入法的操作
				bottomWindow.getWindow().clearFlags(
						WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

				bottomWindow.getWindow().setGravity(Gravity.BOTTOM);

				// 底部弹窗的标题
				TextView tvJianChaNeiRongResultTitle = (TextView) buttomJianChaNeiRongItemLayout
						.findViewById(R.id.tvJianChaNeiRongResultTitle);

				// 查询出来检查记录,根据条件显示或者隐藏
				final EditText edtJianChaJiLu = (EditText) buttomJianChaNeiRongItemLayout
						.findViewById(R.id.edtJianChaJiLu);

				edtJianChaJiLu.setVisibility(View.GONE);

				// 查询出合格的checkbox
				final CheckBox cbHeGe = (CheckBox) buttomJianChaNeiRongItemLayout
						.findViewById(R.id.cbHeGe);

				// 基本合格
				final CheckBox cbJiBenHeGe = (CheckBox) buttomJianChaNeiRongItemLayout
						.findViewById(R.id.cbJiBenHeGe);

				// 不合格
				final CheckBox cbBuHeGe = (CheckBox) buttomJianChaNeiRongItemLayout
						.findViewById(R.id.cbBuHeGe);

				// 清空
				cbHeGe.setChecked(false);
				cbJiBenHeGe.setChecked(false);
				cbBuHeGe.setChecked(false);

				final EditText edtJianChaNeiRongResult = (EditText) buttomJianChaNeiRongItemLayout
						.findViewById(R.id.edtJianChaNeiRongResult);
				edtJianChaNeiRongResult.setText("");

				// 底部Window 的返回按钮
				ViewGroup btnBottomBack = (ViewGroup) buttomJianChaNeiRongItemLayout
						.findViewById(R.id.btnBack);

				btnBottomBack.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						bottomWindow.dismiss();
					}
				});

				final ViewGroup btnSure = (ViewGroup) buttomJianChaNeiRongItemLayout
						.findViewById(R.id.btnSure);

				// 三个选择框的监听器
				OnCheckedChangeListener onCheckedChangeListener = new OnCheckedChangeListener() {

					@Override
					public void onCheckedChanged(CompoundButton buttonView,
												 boolean isChecked) {
						// 清空
						cbHeGe.setChecked(false);
						cbJiBenHeGe.setChecked(false);
						cbBuHeGe.setChecked(false);

						buttonView.setChecked(isChecked);

						if (buttonView == cbBuHeGe && cbBuHeGe.isChecked()) {

							edtJianChaNeiRongResult.setVisibility(View.VISIBLE);

						} else {
							edtJianChaNeiRongResult
									.setVisibility(View.INVISIBLE);
						}

					}
				};

				cbHeGe.setOnCheckedChangeListener(onCheckedChangeListener);
				cbJiBenHeGe.setOnCheckedChangeListener(onCheckedChangeListener);
				cbBuHeGe.setOnCheckedChangeListener(onCheckedChangeListener);

				/**
				 * 产地环境安全性
				 */
				if (viewGroup == rlNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang) {

					tvJianChaNeiRongResultTitle.setText(getResources()
							.getString(R.string.duchaxuncha_item_item1));

					if (dataBean
							.checkNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang()) {
						JianChaJieGuo jianChaJieGuo = dataBean.data
								.getJianChaJieGuos()[0];

						if (jianChaJieGuo.getId() == 3) {

							cbBuHeGe.setChecked(true);

							if (CharsetUtil.isNotNull(jianChaJieGuo
									.getProblem())) {
								edtJianChaNeiRongResult.setText(jianChaJieGuo
										.getProblem());

							}

						} else if (jianChaJieGuo.getId() == 2) {
							cbJiBenHeGe.setChecked(true);

						} else if (jianChaJieGuo.getId() == 1) {

							cbHeGe.setChecked(true);

						}

					}

					btnSure.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {

							JianChaJieGuo jianChaJieGuo = null;

							if (cbHeGe.isChecked()) {

								jianChaJieGuo = new JianChaJieGuo(1, cbHeGe
										.getText().toString());

							} else if (cbJiBenHeGe.isChecked()) {
								jianChaJieGuo = new JianChaJieGuo(2,
										cbJiBenHeGe.getText().toString());

							} else if (cbBuHeGe.isChecked()) {

								String problem = edtJianChaNeiRongResult
										.getText().toString().trim();

								if (!CharsetUtil.isNotNull(problem)) {
									Toast.makeText(getActivity(),
											"请输入存在的问题...", Toast.LENGTH_SHORT)
											.show();
									return;
								}

								jianChaJieGuo = new JianChaJieGuo(3, cbBuHeGe
										.getText().toString(), problem);
							}

							dataBean.data.getJianChaJieGuos()[0] = jianChaJieGuo;

							onClickExecute
									.sureNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang();

							SerliazableUtil.saveTemp(dataBean.data,
									user.getUsername());

							bottomWindow.dismiss();

						}
					});

				}

				/**
				 * 点击生产经营规范性
				 */
				if (viewGroup == rlNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang) {

					tvJianChaNeiRongResultTitle.setText(getResources()
							.getString(R.string.duchaxuncha_item_item2));

					if (dataBean
							.checkNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang()) {

						JianChaJieGuo jianChaJieGuo = dataBean.data
								.getJianChaJieGuos()[1];

						if (jianChaJieGuo.getId() == 3) {

							cbBuHeGe.setChecked(true);

							if (CharsetUtil.isNotNull(jianChaJieGuo
									.getProblem())) {
								edtJianChaNeiRongResult.setText(jianChaJieGuo
										.getProblem());
							}

						} else if (jianChaJieGuo.getId() == 2) {
							cbJiBenHeGe.setChecked(true);

						} else if (jianChaJieGuo.getId() == 1) {

							cbHeGe.setChecked(true);

						}

					}

					btnSure.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {

							JianChaJieGuo jianChaJieGuo = null;

							if (cbHeGe.isChecked()) {

								jianChaJieGuo = new JianChaJieGuo(1, cbHeGe
										.getText().toString());

							} else if (cbJiBenHeGe.isChecked()) {
								jianChaJieGuo = new JianChaJieGuo(2,
										cbJiBenHeGe.getText().toString());
							} else if (cbBuHeGe.isChecked()) {
								String problem = edtJianChaNeiRongResult
										.getText().toString().trim();

								if (!CharsetUtil.isNotNull(problem)) {
									Toast.makeText(getActivity(),
											"请输入存在的问题...", Toast.LENGTH_SHORT)
											.show();
									return;
								}

								jianChaJieGuo = new JianChaJieGuo(3, cbBuHeGe
										.getText().toString(), problem);
							}

							dataBean.data.getJianChaJieGuos()[1] = jianChaJieGuo;

							sureNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang();

							SerliazableUtil.saveTemp(dataBean.data,
									user.getUsername());

							bottomWindow.dismiss();

						}
					});
				}

				/**
				 * 点击质量的安全性
				 */
				if (viewGroup == rlNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang) {
					tvJianChaNeiRongResultTitle.setText(getResources()
							.getString(R.string.duchaxuncha_item_item3));

					if (dataBean
							.checkNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang()) {

						JianChaJieGuo jianChaJieGuo = dataBean.data
								.getJianChaJieGuos()[2];

						if (jianChaJieGuo.getId() == 3) {

							cbBuHeGe.setChecked(true);

							if (CharsetUtil.isNotNull(jianChaJieGuo
									.getProblem())) {
								edtJianChaNeiRongResult.setText(jianChaJieGuo
										.getProblem());

							}

						} else if (jianChaJieGuo.getId() == 2) {
							cbJiBenHeGe.setChecked(true);

						} else if (jianChaJieGuo.getId() == 1) {

							cbHeGe.setChecked(true);

						}

					}

					btnSure.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {

							JianChaJieGuo jianChaJieGuo = null;

							if (cbHeGe.isChecked()) {

								jianChaJieGuo = new JianChaJieGuo(1, cbHeGe
										.getText().toString());

							} else if (cbJiBenHeGe.isChecked()) {
								jianChaJieGuo = new JianChaJieGuo(2,
										cbJiBenHeGe.getText().toString());
							} else if (cbBuHeGe.isChecked()) {
								String problem = edtJianChaNeiRongResult
										.getText().toString().trim();

								if (!CharsetUtil.isNotNull(problem)) {
									Toast.makeText(getActivity(),
											"请输入存在的问题...", Toast.LENGTH_SHORT)
											.show();
									return;
								}

								jianChaJieGuo = new JianChaJieGuo(3, cbBuHeGe
										.getText().toString(), problem);

							}

							dataBean.data.getJianChaJieGuos()[2] = jianChaJieGuo;

							sureNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang();

							SerliazableUtil.saveTemp(dataBean.data,
									user.getUsername());

							bottomWindow.dismiss();

						}
					});
				}

				/**
				 * 点击包装标识合法性
				 */
				if (viewGroup == rlNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu) {
					tvJianChaNeiRongResultTitle.setText(getResources()
							.getString(R.string.duchaxuncha_item_item4));

					if (dataBean
							.checkNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu()) {

						JianChaJieGuo jianChaJieGuo = dataBean.data
								.getJianChaJieGuos()[3];

						if (jianChaJieGuo.getId() == 3) {

							cbBuHeGe.setChecked(true);

							if (CharsetUtil.isNotNull(jianChaJieGuo
									.getProblem())) {
								edtJianChaNeiRongResult.setText(jianChaJieGuo
										.getProblem());

							}

						} else if (jianChaJieGuo.getId() == 2) {
							cbJiBenHeGe.setChecked(true);

						} else if (jianChaJieGuo.getId() == 1) {

							cbHeGe.setChecked(true);

						}

					}

					btnSure.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {

							JianChaJieGuo jianChaJieGuo = null;

							if (cbHeGe.isChecked()) {

								jianChaJieGuo = new JianChaJieGuo(1, cbHeGe
										.getText().toString());

							} else if (cbJiBenHeGe.isChecked()) {
								jianChaJieGuo = new JianChaJieGuo(2,
										cbJiBenHeGe.getText().toString());
							} else if (cbBuHeGe.isChecked()) {
								String problem = edtJianChaNeiRongResult
										.getText().toString().trim();

								if (!CharsetUtil.isNotNull(problem)) {
									Toast.makeText(getActivity(),
											"请输入存在的问题...", Toast.LENGTH_SHORT)
											.show();
									return;
								}

								jianChaJieGuo = new JianChaJieGuo(3, cbBuHeGe
										.getText().toString(), problem);
							}

							dataBean.data.getJianChaJieGuos()[3] = jianChaJieGuo;

							sureNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu();

							SerliazableUtil.saveTemp(dataBean.data,
									user.getUsername());

							bottomWindow.dismiss();

						}
					});
				}

				/**
				 * 点击其他
				 */
				if (viewGroup == rlNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu) {
					tvJianChaNeiRongResultTitle.setText(getResources()
							.getString(R.string.duchaxuncha_item_item5));

					if (dataBean
							.checkNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu()) {

						JianChaJieGuo jianChaJieGuo = dataBean.data
								.getJianChaJieGuos()[4];

						if (jianChaJieGuo.getId() == 3) {

							cbBuHeGe.setChecked(true);

							if (CharsetUtil.isNotNull(jianChaJieGuo
									.getProblem())) {
								edtJianChaNeiRongResult.setText(jianChaJieGuo
										.getProblem());

							}

						} else if (jianChaJieGuo.getId() == 2) {
							cbJiBenHeGe.setChecked(true);

						} else if (jianChaJieGuo.getId() == 1) {

							cbHeGe.setChecked(true);

						}

					}

					btnSure.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {

							JianChaJieGuo jianChaJieGuo = null;

							if (cbHeGe.isChecked()) {

								jianChaJieGuo = new JianChaJieGuo(1, cbHeGe
										.getText().toString());

							} else if (cbJiBenHeGe.isChecked()) {
								jianChaJieGuo = new JianChaJieGuo(2,
										cbJiBenHeGe.getText().toString());
							} else if (cbBuHeGe.isChecked()) {
								String problem = edtJianChaNeiRongResult
										.getText().toString().trim();

								if (!CharsetUtil.isNotNull(problem)) {
									Toast.makeText(getActivity(),
											"请输入存在的问题...", Toast.LENGTH_SHORT)
											.show();
									return;
								}

								jianChaJieGuo = new JianChaJieGuo(3, cbBuHeGe
										.getText().toString(), problem);
							}

							dataBean.data.getJianChaJieGuos()[4] = jianChaJieGuo;

							sureNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu();

							SerliazableUtil.saveTemp(dataBean.data,
									user.getUsername());

							bottomWindow.dismiss();

						}
					});
				}

				/**
				 * 点击其他
				 */
				if (viewGroup == rlDuChaXunChaQiTa) {
					tvJianChaNeiRongResultTitle.setText(getResources()
							.getString(R.string.duchaxuncha_item_item6));

					if (dataBean.checkDuChaXunChaQiTa()) {

						JianChaJieGuo jianChaJieGuo = dataBean.data
								.getJianChaJieGuos()[5];

						if (jianChaJieGuo.getId() == 3) {

							cbBuHeGe.setChecked(true);

							if (CharsetUtil.isNotNull(jianChaJieGuo
									.getProblem())) {
								edtJianChaNeiRongResult.setText(jianChaJieGuo
										.getProblem());

							}

						} else if (jianChaJieGuo.getId() == 2) {
							cbJiBenHeGe.setChecked(true);

						} else if (jianChaJieGuo.getId() == 1) {

							cbHeGe.setChecked(true);

						}

					}

					btnSure.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {

							JianChaJieGuo jianChaJieGuo = null;

							if (cbHeGe.isChecked()) {

								jianChaJieGuo = new JianChaJieGuo(1, cbHeGe
										.getText().toString());

							} else if (cbJiBenHeGe.isChecked()) {
								jianChaJieGuo = new JianChaJieGuo(2,
										cbJiBenHeGe.getText().toString());
							} else if (cbBuHeGe.isChecked()) {
								String problem = edtJianChaNeiRongResult
										.getText().toString().trim();

								if (!CharsetUtil.isNotNull(problem)) {
									Toast.makeText(getActivity(),
											"请输入存在的问题...", Toast.LENGTH_SHORT)
											.show();
									return;
								}

								jianChaJieGuo = new JianChaJieGuo(3, cbBuHeGe
										.getText().toString(), problem);
							}

							dataBean.data.getJianChaJieGuos()[5] = jianChaJieGuo;

							sureDuChaXunChaQiTa();

							SerliazableUtil.saveTemp(dataBean.data,
									user.getUsername());

							bottomWindow.dismiss();

						}
					});
				}

			}

			if (viewGroup == rlZhengGaiYiJianItemLayout) {

				bottomWindow.show();

				// 让底部的宽度和屏幕的宽度一致
				ViewGroup bottomBeiJianDanWeiWindowLayout = (ViewGroup) getActivity()
						.getLayoutInflater().inflate(
								R.layout.bottom_photodetail_comment, null);

				bottomBeiJianDanWeiWindowLayout.setMinimumWidth(getActivity()
						.getWindowManager().getDefaultDisplay().getWidth());

				// 设置底部布局
				bottomWindow.setContentView(bottomBeiJianDanWeiWindowLayout);

				// 弹出输入法的操作
				bottomWindow.getWindow().clearFlags(
						WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

				bottomWindow.getWindow().setGravity(Gravity.BOTTOM);

				TextView tvTitle = (TextView) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.tvTitle);

				tvTitle.setText(getString(R.string.jiandujiancha_item_jianchaneirong_zhenggaiyijian));

				final TextView edtContent = (TextView) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.edtCommentPhoto);

				edtContent
						.setHint(getString(R.string.jiandujiancha_item_jianchaneirong_zhenggaiyijian_hint));

				if (dataBean.checkZhengGaiYiJian()) {

					edtContent.setText(dataBean.data.getZhengGaiYiJian());

				}

				ViewGroup btnBack = (ViewGroup) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.btnBack);

				ViewGroup btnSure = (ViewGroup) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.btnSure);

				btnSure = (ViewGroup) bottomBeiJianDanWeiWindowLayout
						.findViewById(R.id.btnSure);

				btnSure.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						String zhengGaiYiJian = edtContent.getText().toString()
								.trim();

						if (CharsetUtil.isNotNull(zhengGaiYiJian)) {

							dataBean.data.setZhengGaiYiJian(zhengGaiYiJian);

							sureZhengGaiYiJian();

							bottomWindow.dismiss();
						} else {
							Toast.makeText(
									getActivity(),
									getString(R.string.jiandujiancha_item_jianchaneirong_zhenggaiyijian_hint),
									Toast.LENGTH_SHORT).show();
						}

					}
				});

				btnBack.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {

						bottomWindow.dismiss();

					}
				});

			}

			/**
			 * 点击拍照的时候
			 */
			if (viewGroup == rl_jiandujiancha_item_paizhao) {
				if(InitApplication.organization!=null){
					Intent to_paizhao_intent = new Intent(getActivity(),
							PaiZhaoActivity.class);

					to_paizhao_intent.putExtra("photos",
							(Serializable) dataBean.data.getPhotos());

					startActivityForResult(to_paizhao_intent, PAIZHAO_REQUEST_CODE);
				}else{
					DialogUtil.showMessageDialog("请填写受检对象..", null, getActivity());
				}
			}

			/**
			 * 点击签名的时候
			 */
			if (viewGroup == rl_jiandujiancha_item_qianming) {
				if (!ImageUtil.hasStore()) {
					Toast.makeText(getActivity(), "未检测到存储卡", Toast.LENGTH_LONG)
							.show();
				} else {
					Intent to_qianming = new Intent(getActivity(),
							QianMingActivity.class);
					to_qianming.putExtra("qianmingpath",
							dataBean.data.getQianMingPath());

					startActivityForResult(to_qianming, QIANMING_REQUEST_CODE);
				}

			}
		}
	}

	/**
	 * 数据对象
	 */
	private class DataBean {

		private DuChaXunChaRecord data = null;

		public DuChaXunChaRecord getData() {
			return data;
		}

		public boolean checkQuYu() {

			boolean result = false;

			for (Town town : data.getTowns()) {

				if (town != null) {
					result = true;

					break;
				}

			}

			return result;

		}

		public String getQuYuString() {

			StringBuffer result = new StringBuffer();

			for (int i = 0; i < data.getTowns().length; i++) {

				Town town = data.getTowns()[i];

				if (town != null) {

					if (!CharsetUtil.isNotNull(town.getName())) {

						town = db.queryTownById(town.getCode());
					}

					result.append(town.getName());

					result.append("--");
				}

			}

			if (result.length() > 0) {

				return result.substring(0, result.length() - 2);
			} else {

				return result.toString();
			}

		}

		public String getKnowCode() {

			if (data.getTowns()[3] != null) {
				return data.getTowns()[3].getCode();
			} else if (data.getTowns()[2] != null) {

				return data.getTowns()[2].getCode();
			} else if (data.getTowns()[1] != null) {

				return data.getTowns()[1].getCode();
			} else if (data.getTowns()[0] != null) {

				return data.getTowns()[0].getCode();
			} else {
				return null;
			}

		}

		public boolean checkBeiJianDanWei() {
			if (data.getBeiJianDanWei() != null
					&& !"-1".equals(data.getBeiJianDanWei().getId())) {
				return true;
			} else {
				return false;
			}
		}

		public String getBeiJianDanWeiString() {
			if (data.getBeiJianDanWei() != null
					&& !"-1".equals(data.getBeiJianDanWei().getId())) {
				return data.getBeiJianDanWei().getName();
			} else {
				return null;
			}

		}

		public boolean checkTongXunDiZhi() {

			if (checkBeiJianDanWei()
					&& CharsetUtil.isNotNull(data.getBeiJianDanWei()
					.getAddress())) {
				return true;
			} else {
				return false;
			}

		}

		public boolean checkFuZeRen() {

			if (checkBeiJianDanWei()
					&& CharsetUtil.isNotNull(data.getBeiJianDanWei()
					.getCharge())) {
				return true;
			} else {
				return false;
			}

		}

		public boolean checkLianXiFangShi() {

			if (checkBeiJianDanWei()
					&& CharsetUtil.isNotNull(data.getBeiJianDanWei()
					.getMobile())) {
				return true;
			} else {
				return false;
			}

		}

		public boolean checkJianChaDanWei() {
			if (data.getJianChaDanWeis().size() > 0) {
				return true;
			} else {
				return false;
			}
		}

		public String getJianChaDanWeiString() {

			StringBuffer jianChaDanWeiTxt = new StringBuffer();

			for (int i = 0; i < data.getJianChaDanWeis().size(); i++) {

				JianChaDanWei jianChaDanWei = data.getJianChaDanWeis().get(i);

				jianChaDanWeiTxt.append(jianChaDanWei.getName());

				jianChaDanWeiTxt.append(". ");

				if (i < data.getJianChaDanWeis().size() - 1) {

					jianChaDanWeiTxt.append("\n");

				}

			}

			return jianChaDanWeiTxt.toString();

		}

		public boolean checkJianChaRenYuan() {
			if (data.getJianChaReYuans().size() > 0) {
				return true;
			} else {
				return false;
			}

		}

		public String getJianChaRenYuanString() {

			StringBuffer jianChaRenYuanTxt = new StringBuffer();

			for (int i = 0; i < data.getJianChaReYuans().size(); i++) {

				JianChaRenYuan jianChaRenYuan = data.getJianChaReYuans().get(i);

				jianChaRenYuanTxt.append(jianChaRenYuan.getName());

				jianChaRenYuanTxt.append(". ");

			}

			return jianChaRenYuanTxt.toString();

		}

		/**
		 * 检查被检单位是否填写
		 *
		 * @return
		 */
		public boolean checkJianChaHangYe() {
			if (data.getJianChaHangYes().size() > 0) {
				return true;
			} else {
				return false;
			}
		}

		public String getJianChaHangYeString() {

			StringBuffer jianChaHangYeStr = new StringBuffer();

			for (int i = 0; i < data.getJianChaHangYes().size(); i++) {

				JianChaHangYe jianChaHangYe = data.getJianChaHangYes().get(i);

				jianChaHangYeStr.append(jianChaHangYe.getName());

				jianChaHangYeStr.append(". ");

				if (i < data.getJianChaHangYes().size() - 1) {
					jianChaHangYeStr.append("\n");
				}

			}

			return jianChaHangYeStr.toString();

		}

		/**
		 * 检查记录
		 */
		public boolean checkJianChaJiLu() {

			if (CharsetUtil.isNotNull(data.getJianChaJiLu())) {
				return true;
			} else {
				return false;
			}

		}

		public boolean checkNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang() {

			if (data.getJianChaJieGuos()[0] == null) {
				return false;
			} else {
				return true;
			}

		}

		public boolean checkNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang() {

			if (data.getJianChaJieGuos()[1] == null) {
				return false;
			} else {
				return true;
			}

		}

		/**
		 * 检测产品质量安全性
		 */
		public boolean checkNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang() {

			if (data.getJianChaJieGuos()[2] == null) {
				return false;
			} else {
				return true;
			}
		}

		/**
		 * 检测包装标识合法性
		 */
		public boolean checkNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu() {

			if (data.getJianChaJieGuos()[3] == null) {
				return false;
			} else {
				return true;
			}
		}

		public boolean checkNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu() {
			if (data.getJianChaJieGuos()[4] == null) {
				return false;
			} else {
				return true;
			}
		}

		public boolean checkDuChaXunChaQiTa() {
			if (data.getJianChaJieGuos()[5] == null) {
				return false;
			} else {
				return true;
			}
		}

		/**
		 * 检测记录情况是否填写
		 */
		public boolean checkJiLuQingKuang() {

			return checkNongChanPinAnQuanShouYaoZeRenLuoShiQingKuang()
					|| checkNongYaoTouRuPinCunFangHeShiYongJiLuQingKuang()
					|| checkNongYaoJianGeQiHeShouYaoXiuYaoQiZhiDuLuoShiQingKuang()
					|| checkNongChanPinShouHuoHeChuLanRiQiShuLiangJiXiaoShouJiLu()
					|| checkNongChanPinZiJianJianCeJiXiangGuanJianCeJiLu()
					|| checkDuChaXunChaQiTa();

		}

		/**
		 * 检测整改意见
		 */
		public boolean checkZhengGaiYiJian() {

			if (CharsetUtil.isNotNull(dataBean.data.getZhengGaiYiJian())) {
				return true;
			} else {
				return false;
			}

		}

		/**
		 * 检测拍照
		 */
		public boolean checkPaiZhao() {

			if (dataBean.data.getUploadPhoto().size() > 0) {

				return true;
			} else {
				return false;
			}

		}

		/**
		 * 检测签名
		 *
		 * @return
		 */
		public boolean checkQianMing() {

			if (CharsetUtil.isNotNull(data.getQianMingPath())) {
				return true;
			} else {
				return false;
			}

		}

	}

	@Override
	public void onDestroy() {
		if (db != null) {
			db.close();
		}
		InitApplication.organization=null;

		super.onDestroy();
	};

	/**
	 * 提交数据
	 */
	public boolean submit() {

		if (!dataBean.checkQuYu()) {

			DialogUtil.showMessageDialog("请选择所属区域..", null, getActivity());

			return false;
		}

		if (!dataBean.checkBeiJianDanWei()) {

			DialogUtil.showMessageDialog("请选择受检对象..", null, getActivity());
			return false;
		}

		int danWeiCount = db.queryCountBeiJianDanWeiByName(dataBean.data
				.getBeiJianDanWei().getName(),dataBean.getKnowCode());

		// 如果在数据库中没有找到,说明用户不是选择的,是自己输入的,并且选择了创建
		if (dataBean.getData().getBeiJianDanWei().isCreateShouJianDanWei()
				&& danWeiCount < 1) {

			if (!dataBean.checkTongXunDiZhi()) {

				DialogUtil.showMessageDialog("请填写通讯地址..", null, getActivity());

				return false;
			}

			if (!dataBean.checkFuZeRen()) {

				DialogUtil.showMessageDialog("请填写负责人..", null, getActivity());

				return false;
			}
			if (!dataBean.checkLianXiFangShi()) {

				DialogUtil.showMessageDialog("请填写联系方式..", null, getActivity());

				return false;
			}

		}

		if (!dataBean.checkJianChaDanWei()) {

			DialogUtil.showMessageDialog("请选择检查单位..", null, getActivity());

			return false;
		}

		if (!dataBean.checkJianChaRenYuan()) {

			DialogUtil.showMessageDialog("请选择检查人员..", null, getActivity());

			return false;
		}

		if (!dataBean.checkJianChaHangYe()) {

			DialogUtil.showMessageDialog("请选择检查行业..", null, getActivity());

			return false;
		}

		if (!dataBean.checkJiLuQingKuang()) {

			DialogUtil.showMessageDialog("请填写相关记录情况..", null, getActivity());

			return false;
		}

		if (toggleZhengGaiYiJian()) {

			if (!dataBean.checkZhengGaiYiJian()) {

				DialogUtil.showMessageDialog("请填写整改意见..", null, getActivity());

				return false;

			}

		}

		if (!dataBean.checkPaiZhao()) {
			DialogUtil.showMessageDialog("请拍照或选择上传照片..", null, getActivity());

			return false;
		}

		if (!dataBean.checkQianMing()) {
			DialogUtil.showMessageDialog("请填写签名 ..", null, getActivity());

			return false;
		}

		// 如果不是编辑模式
		if (!isEditor) {

			final Calendar calendar = new GregorianCalendar();

			if (CommonConstants.isNetworkConnected(getActivity())) {

				/**
				 * 网络时间的初始化
				 */
				new AsyncTask<Integer, Integer, Integer>() {

					private CustomDialog customDialog = null;

					// 检测是否走的网络时间
					private boolean isErr = true;

					@Override
					protected void onPreExecute() {

						if (customDialog == null) {

							customDialog = new CustomDialog(getActivity());

							customDialog.setMessage("尝试读取网络时间请等待..");

							customDialog.showWait();

						}

						super.onPreExecute();
					}

					@Override
					protected Integer doInBackground(Integer... params) {

						URL url = null;

						URLConnection uc = null;

						try {
							url = new URL("http://www.baidu.com/");// 取得资源对象
							uc = url.openConnection();// 生成连接对象
							uc.connect(); // 发出连接
							long milliseconds = uc.getDate(); // 取得网站日期时间
							calendar.setTimeInMillis(milliseconds);

							isErr = false;

						} catch (MalformedURLException e) {
						} catch (IOException e) {
						}

						return null;
					}

					protected void onPostExecute(Integer result) {

						if (customDialog != null) {
							customDialog.dismiss();

							if (isErr) {
								Toast.makeText(getActivity(),
										"读取网络时间失败..使用本地时间..",
										Toast.LENGTH_SHORT).show();
							}

						}

					};

				}.execute();

			} else {

				Toast.makeText(getActivity(), "未检测到网络..使用本地时间..",
						Toast.LENGTH_SHORT).show();

			}

			String time = new SimpleDateFormat("yyyy-MM-dd").format(calendar
					.getTime());

			dataBean.data.setTime(time);

		}

		String message = "";

		// 编辑模式
		if (isEditor) {

			message = "编辑记录成功..";

			SerliazableUtil.saveTemp(dataBean.data, user.getUsername());

			dataBean.data = null;

			isEditor = false;

			ScrollView scrollView = (ScrollView) getActivity().findViewById(
					R.id.scrollViewNewRecord);

			scrollView.scrollTo(0, 0);

			onActivityCreated(null);

			Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();

		} else {

			// 增加模式
			dataBean.data.setState(1);

			SerliazableUtil.saveTemp(dataBean.data, user.getUsername());

			SerliazableUtil.deleteDuChaXunChaTemp();

			message = "增加新记录成功..";
		}

		dataBean.data = null;

		ScrollView scrollView = (ScrollView) getActivity().findViewById(
				R.id.scrollViewNewRecord);

		scrollView.scrollTo(0, 0);

		onActivityCreated(null);

		Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();

		return true;

	}

	/**
	 * 加�d��模式
	 *
	 * @param record
	 */
	public void loadEditMode(DuChaXunChaRecord record) {

		isEditor = true;

		dataBean.data = record;

		ScrollView scrollView = (ScrollView) getActivity().findViewById(
				R.id.scrollViewNewRecord);

		scrollView.scrollTo(0, 0);

		onActivityCreated(null);

		Toast.makeText(getActivity(), "进入编辑模式成功..", Toast.LENGTH_SHORT).show();

	}

	public boolean isEditor() {
		return isEditor;
	}

	/**
	 * 获得当前记录的ID
	 */
	public String getRecordId() {
		return dataBean.getData().getFileId();
	}

	/**
	 * 切换整改意见的显示状态
	 */
	private boolean toggleZhengGaiYiJian() {

		boolean isNotHeGe = false;

		JianChaJieGuo[] jianchaChaJieGuos = dataBean.data.getJianChaJieGuos();

		for (int i = 0; i < jianchaChaJieGuos.length; i++) {

			JianChaJieGuo jianChaJieGuo = jianchaChaJieGuos[i];

			if (jianChaJieGuo != null && jianChaJieGuo.getId() == 3) {

				isNotHeGe = true;
				break;
			}

		}

		if (isNotHeGe) {
			rlZhengGaiYiJianItemLayout.setVisibility(View.VISIBLE);

		} else {
			rlZhengGaiYiJianItemLayout.setVisibility(View.GONE);
		}

		return isNotHeGe;
	}
}
